<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Log in</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
</head>
<body class="hold-transition login-page">
<div class="container">
<div class="login-box" >
    <div class="login-logo">
        <a href="#"><b>用户表-</b></a>
    </div>

        <form class="form-horizontal" role="form">
            <div class="form-group">
                <label for="usernameId" class="col-sm-2 control-label">用户:</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="usernameId">
                </div>
                <div class="form-group">
                    <label for="passwordId" class="col-sm-2 control-label">密码:</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="passwordId" >
                    </div>
                </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox">请记住用户
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default">登录</button>
                        </div>
                    </div>
            </div>

        </form>

    </div>


</div>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="plugins/iCheck/icheck.min.js"></script>
<script>
    $(function () {
        $(".btn").click(doLogin);
    });
    function doLogin(){
        let uName=$("#usernameId").val();
        let uPwd=$("#passwordId").val();
        let url=`http://localhost:80/user/login/${uName}/${uPwd}`;
        $.ajax({
            url:url,
            crossDomain:true,
            xhrFields:{withCredentials:true},
            success(result){
                if(result.state==1){
                    //跳转到indexUI对应的页面
                    //原生写法(创建cookie)
                  //  document.cookie=`username=${result.data}; path=/`;
                    //借助jquery中的cookie插件
                    //$.cookie('username',result.data);
                    location.href="/user.html";
                }else{
                    $(".login-box-msg").html(result.message);
                }
                return false;//防止刷新时重复提交
            }});
    }
</script>
</body>
</html>
